<?php
namespace api\models;

use api\models\base\BaseForm;


class OrderForm extends BaseForm
{
    private $rank2buy = 100;

    /**
     * 检查队列位置,是否能够购买
     *
     * @param int $uid
     * @return array
     */
    public function checkQueue2buy( $uid = 0 )
    {
        $ret2Pager = [ 'status' => false, 'msg' => '未在队列当中,请从新尝试' ];
        if( !$uid ){ return $ret2Pager; }

        $currentRank2Uid = \Yii::$app->redis->zrank( 'by_user', $uid );

        if( !is_null( $currentRank2Uid ) && $currentRank2Uid < $this->rank2buy ){
            return [ 'status' => true, 'msg' => '在可购买队列范围当中', 'rank' => $currentRank2Uid ];
        }

        return [ 'status' => false, 'msg' => '不在可购买队列范围当中', 'rank' => $currentRank2Uid ];
    }
}
